package fontys.time;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Willem Sporen , Implementatie: Elton Figaroa
 */
public class Appointment {

    /*
     * Fields
     */
    /**
     * An appointment has a subject. This value may be empty.
     */
    String subject;
    /**
     * An appointment has a period.
     */
    IPeriod period;
    /**
     * An appointment has 0 or more contacts.
     */
    ArrayList<Contact> contacts;

    /**
     * Constructor for the Appointment class.
     *
     * @param subj The subject of this appointment. May be empty.
     * @param per The period of this appointment.
     */
    public Appointment(String subj, IPeriod per) {
        this.subject = subj;
        this.period= per;
        this.contacts= new ArrayList<Contact>();
    }

    // Methods
    /**
     * Get the subject of this appointment.
     * @return The subject as a String.
     */
    public String getSubject() {
        return subject;
    }
    
    /**
     * Get the period of this appointment.
     * @return The period as a IPeriod.
     */
    public IPeriod getPeriod() {
        return period;
    }
    
    /**
     * Get all the invited members of this Appointment.
     * @return An Iterator<Contact> object containing all the invited members of
     * this appointment.
     */
    public Iterator<Contact> invitees() {
        return contacts.iterator();
    }
    
    /**
     * Add a contact to the current contacts list of this appointment. A check
     * should be in place to ensure that, when adding this contact, his/her
     * schedule does not get conflicted.
     * @param c The contact that should be added.
     * @return True when the contact was succesfully added, False in all other
     * cases.
     */
    public boolean addContact(Contact c) {
        /*A check should be in place to determine whether adding contact c to
         * this appointment would conflict with this schedule. If this is the
         * case, don't add him to the appointment and return a false.
         */
        if (this.contacts.add(c)) {
            return true;
        } else {
            return false;
        } 
    }
    
    /**
     * Remove a contact from the contacts list of this appointment.
     * @param c The contact that should be removed.
     */
    public void removeContact(Contact c) {
        contacts.remove(c);
    }
}
